<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="common/include :: header('食材列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="customer-form">
                <div class="select-list">
                    <ul>
                        <li>
                            关键字：<input type="text" name="keyword" placeholder="模糊查询食材名称"/>
                        </li>
                        <li>
                            销售状态：
                            <select name="state" th:with="items=${@dict.getType('business_goods_state')}">
                                <option value="">所有</option>
                                <option th:each="item : ${items}" th:text="${item.label}"
                                        th:value="${item.value}"></option>
                            </select>
                        </li>
                        <li>
                            食材种类：
                            <select name="type" th:with="items=${@dict.getType('business_ingredient_type')}">
                                <option value="">所有</option>
                                <option th:each="item : ${items}" th:text="${item.label}"
                                        th:value="${item.value}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="business:ingredients:add">
                <i class="fa fa-plus"></i> 添加
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<div class="modal inmodal fade" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-body" style="text-align:center;">
                <img id="imageSrc" src="" alt="" width="300px" height="auto">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
<th:block th:include="common/include :: footer"/>
<script th:inline="javascript">
    var ingredientTypeData = [[${@dict.getType('business_ingredient_type')}]];

    var removeFlag = [[${@permission.hasPermi('business:ingredients:remove')}]];
    var saleOnFlagTemp = [[${@permission.hasPermi('business:ingredients:saleOn')}]];
    var saleOffFlagTemp = [[${@permission.hasPermi('business:ingredients:saleOff')}]];
    var editFlag = [[${@permission.hasPermi('business:ingredients:edit')}]];
    var prefix = ctx + "/business/ingredients";
    $(function () {
        var options = {
            url: prefix + "/query",
            createUrl: prefix + "/addPage",
            updateUrl: prefix + "/editPage?id={id}",
            removeUrl: prefix + "/remove",
            uniqueId: 'id',
            modalName: "食材",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '编号',
                    visible: false
                },
                {
                    field: 'ingredientName',
                    title: '食材名称'
                },
                {
                    field: 'imageSrc',
                    title: '食材图片',
                    formatter: function (value, row, index) {
                        return row.imageSrc ? '<img src="' + row.imageSrc + '" style="width: 50px"></img>' : '-';
                    }
                },
                {
                    field: 'type',
                    title: '食材种类',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(ingredientTypeData, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var editFlagTemp = editFlag;
                        var removeFlagTemp = removeFlag;

                        var actions = [];

                        if (row.state === 1) {
                            actions.push('<a class="btn btn-warning btn-xs ' + saleOnFlagTemp + '" href="javascript:void(0)" ' +
                                'onclick="saleOff(\'' + row.id + '\')"><i class="fa fa-edit"></i>下架</a> ');
                        } else {
                            // 显示上架按钮
                            actions.push('<a class="btn btn-info btn-xs ' + saleOffFlagTemp + '" href="javascript:void(0)" ' +
                                'onclick="saleOn(\'' + row.id + '\')"><i class="fa fa-edit"></i>上架</a> ');
                        }
                        actions.push('<a class="btn btn-success btn-xs ' + editFlagTemp + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push("<a class='btn btn-danger btn-xs " + removeFlagTemp + "' href='javascript:void(0)' onclick='$.operate.remove(" + row.id + ")'><i class='fa fa-remove'></i>删除</a>");
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });
    function saleOn(id) {
        var url = ctx + '/business/ingredients/saleOn?id=' + id;
        $.operate.get(url);
    }
    function saleOff(id) {
        var url = ctx + '/business/ingredients/saleOff?id=' + id;
        $.operate.get(url);
    }
</script>
</body>
</html>